package com.collect.senegal.zhiScene.zhiWidget.zhiSubmitRecTagView;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.collect.senegal.R;

public class ZHICallResultView extends PopupWindow implements View.OnClickListener {

    private View mMenuView;
    private LinearLayout ll_pop_layout;
    private Context mContext;


    private OnCallResultClickListener mOnCallResultClickListener;

    public ZHICallResultView(Context context) {
        super(context);
        mContext = context;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.popview_call_result, null);
        ll_pop_layout = mMenuView.findViewById(R.id.ll_pop_layout);

        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.PopWindowFromBottom);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0x10000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        this.setClippingEnabled(false);
        mMenuView.findViewById(R.id.tv_ptr).setOnClickListener(this);
        mMenuView.findViewById(R.id.tv_rnr).setOnClickListener(this);
        mMenuView.findViewById(R.id.tv_out_coverage).setOnClickListener(this);
        mMenuView.findViewById(R.id.tv_switch_off).setOnClickListener(this);
        mMenuView.findViewById(R.id.tv_invalid_num).setOnClickListener(this);
        mMenuView.findViewById(R.id.tv_msg_sent).setOnClickListener(this);
        mMenuView.findViewById(R.id.tv_paid).setOnClickListener(this);

        mMenuView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                int height = mMenuView.findViewById(R.id.ll_pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
    }

    @Override
    public void onClick(View v) {
        String cResult = "";
        switch (v.getId()){
            case R.id.tv_ptr:{
                cResult = mContext.getResources().getString(R.string.call_result_ptp);
                break;
            }
            case R.id.tv_rnr:{
                cResult = mContext.getResources().getString(R.string.call_result_rnr);
                break;
            }
            case R.id.tv_fake:{
                cResult = mContext.getResources().getString(R.string.call_result_fake);
                break;
            }
            case R.id.tv_out_coverage:{
                cResult = mContext.getResources().getString(R.string.call_result_out_of_coverage);
                break;
            }
            case R.id.tv_switch_off:{
                cResult = mContext.getResources().getString(R.string.call_result_switched_off);
                break;
            }
            case R.id.tv_invalid_num:{
                cResult = mContext.getResources().getString(R.string.call_result_innvalid_num);
                break;
            }
            case R.id.tv_msg_sent:{
                cResult = mContext.getResources().getString(R.string.call_result_msg_sent);
                break;
            }
            case R.id.tv_paid:{
                cResult = mContext.getResources().getString(R.string.call_result_paid);
                break;
            }
        }
        if (mOnCallResultClickListener != null) {
            mOnCallResultClickListener.onResultClick(cResult);
        }
        dismiss();
    }

    public void setCallResultClickListener(OnCallResultClickListener callResultClickListener) {
        this.mOnCallResultClickListener = callResultClickListener;
    }

    public interface OnCallResultClickListener {
        void onResultClick(String result);
    }

}